<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hello_react</title>
</head>
<body>
    <!-- 准备一个“容器” -->
    <div id="test"></div>

    <!-- 引入 react 核心库 -->
    <script src="../js/react.development.js"></script>
    <!-- 引入 react-dom. 用于支持 react 操作 dom -->
    <script src="../js/react-dom.development.js"></script>
    <!-- 引入babel. 用于将 jsx 转换为 js -->
    <script src="../js/babel.min.js"></script>
    <script type="text/babel"> /* 这里必须写 babel */
        // 创建组件
        class Login extends React.Component {
            // 初始化状态
            state = {
                username:"", // 用户名
                password:"", // 密码
            }
            // 保存用户名到 状态
            saveUsername = (event) => {
                this.setState({
                    username:event.target.value
                })
            }
            // 保存密码到 状态
            savePassword = (event) => {
                this.setState({
                    password: event.target.value
                })
            }
            handleSubmit = (event) => {
                event.preventDefault() // 阻止表单提交  
                const {username,password} = this.state
                alert(`用户名：${username}，密码：${password}`)
            }
            render(){
                return (
                    <form action="" onSubmit={this.handleSubmit}>
                        <input onChange={this.saveUsername} type="text" placeholder="用户名" name="username" />
                        <input onChange={this.savePassword} type="password" placeholder="密码" name="password" />
                        <button>登录</button>
                    </form>
                )
            }
        }
        ReactDOM.render(<Login />,document.getElementById("test"))
    </script>
</body>
</html>